import request from "@/utils/knowrequest";
import { APP_ID, APP_SECRET } from "@/enums/CacheEnum";
import type {CreatBase,RenewBase,DocsFiles,FilesType} from "./types";

class AuthAPI {
	/**
	 * 请求知识库列表
	 */
	static getKnowledgeBase(AuthorizeCode: string) {
		return request<any>({
			// url: "/knowledge_base/list_knowledge_bases",//最新的知识库列表接口
			url: "/knowledge_base/get_all_kbs",
			method: "get",
			headers: {
				token: AuthorizeCode,
			},
		});
	}
	/**
	 * 创建知识库
	 */
	static postCreateBase(AuthorizeCode: string,dpetDataForm:CreatBase) {
		const formData = new FormData();
		formData.append("knowledge_base_name", dpetDataForm.knowledge_base_name);
		formData.append("kb_title", dpetDataForm.kb_title);
		formData.append("deptDescribe", dpetDataForm.deptDescribe);
		return request<any>({
			url: "/knowledge_base/create_knowledge_base",
			method: "post",
			data: formData,
			headers: {
				token: AuthorizeCode,
			},
		});
	}
	/**
	 * 删除知识库
	 */
	static getDeleteBase(AuthorizeCode: string,basename:string) {
		const formData = new FormData();
		formData.append("knowledge_base_name", basename);
		return request<any>({
			url: "/knowledge_base/delete_knowledge_base",
			method: "post",
			data: formData,
			headers: {
				token: AuthorizeCode,
				"Content-Type": "multipart/form-data",
			},
		});
	}
	/**
	 * 获取知识库内的文件 
	 */
	static getBaseFiles(AuthorizeCode: string,basename:string) {
		const formData = {
			knowledge_base_name:basename
		}
		return request<any>({
			url: "/knowledge_base/list_files",
			method: "get",
			params: formData,
			headers: {
				token: AuthorizeCode,
				"Content-Type": "multipart/form-data",
			},
		});
	}
	/**
	 * 获取知识库内的详情文件信息 
	 */
	static getBaseAllFiles(AuthorizeCode: string,basename:string) {
		const formData = {
			knowledge_base_name:basename
		}
		return request<any>({
			url: "/knowledge_base/all_files",
			method: "get",
			params: formData,
			headers: {
				token: AuthorizeCode,
				"Content-Type": "multipart/form-data",
			},
		});
	}
	/**
	 * 更新知识库介绍
	 */
	static getUpdateInfo(AuthorizeCode: string,data:RenewBase) {
		const formData = new FormData();
		formData.append("knowledge_base_name", data.kb_name);
		formData.append("kb_info", data.kb_info);
		formData.append("kb_title", data.kb_title);
		return request<any>({
			url: "/knowledge_base/update_info",
			method: "post",
			data: formData,
			headers: {
				token: AuthorizeCode,
				// "Content-Type": "multipart/form-data",
			},
		});
	}
	/**
	 * 删除知识库内的文件
	 */
	static getDeleteDocs(AuthorizeCode: string,data:DocsFiles) {
	
		const formData ={
			knowledge_base_name:data.kb_name,
			file_names:data.file_names,
			not_refresh_vs_cache:data.not_refresh_vs_cache,
			delete_content:data.delete_content,
		}
		return request<any>({
			url: "/knowledge_base/delete_docs",
			method: "post",
			data: formData,
			headers: {
				token: AuthorizeCode,
			},
		});
	}
	/**
	 * 上传文件到知识库里
	 */
	static postUpdateDocs(AuthorizeCode: string,data:any,formname:string) {	
		console.log(data);
		const formData = new FormData()
		formData.append('files',data)
		formData.append('knowledge_base_name',formname)
		return request<any>({
			url: "/knowledge_base/upload_docs",
			method: "post",
			data: formData,
			headers: {
				token: AuthorizeCode,
				"Content-Type": "multipart/form-data",
			},
		});
	}
	/**
	 * 请求文件信息
	 */
	static postDownloadDoc(AuthorizeCode: string,data:FilesType) {	
		const formData = {
			knowledge_base_name:data.kb_name,
			file_name:data.file_name
		}
		return request<any>({
			url: "/knowledge_base/download_doc",
			method: "get",
			params:formData,
			headers: {
				token: AuthorizeCode,
			},
		});
	}
	/**
	 * 请求文件信息url
	 */
	static gettShowDocs(AuthorizeCode: string,data:FilesType) {	
		const formData = {
			knowledge_base_name:data.kb_name,
			file_name:data.file_name,
			// token:data.token,
		}
		return request<any>({
			url: "/knowledge_base/show_docs",
			method: "get",
			params:formData,
			headers: {
				token: AuthorizeCode,
			},
		});
	}
}

export default AuthAPI;
